<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"
	isELIgnored="false"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html>
<html>
<head>

<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
<meta name="description" content="description of your site" />
<meta name="author" content="author of the site" />
<title>电商平台后台首页</title>
<link rel="stylesheet" href="css/bootstrap.css" />
<link rel="stylesheet" href="css/bootstrap-responsive.css" />
<link rel="stylesheet" href="css/styles.css" />
<link rel="stylesheet" href="css/toastr.css" />
<link rel="stylesheet" href="css/fullcalendar.css" />
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/jquery.knob.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="js/jquery.sparkline.min.js"></script>
<script src="js/toastr.js"></script>
<script src="js/jquery.tablesorter.min.js"></script>
<script src="js/jquery.peity.min.js"></script>
<script src="js/fullcalendar.min.js"></script>
<script src="js/gcal.js"></script>
<script src="js/setup.js"></script>
</head>
<body>

	<%@include file="header.jsp"%>

	<div class="page">
		<div class="page-container">
			<div class="container">
				<div class="row">
					<div class="span12">
						<a href="#newUserModal" data-toggle="modal"
							class="btn btn-success btn pull-right">添加用户</a>
						<h4 class="header">用户列表</h4>
						<button class="btn btn-primary" onclick="batchDelete()">批量删除</button>
						<table class="table table-striped sortable">
							<thead>
								<tr>
									<th></th>
									<th>用户ID</th>
									<th>用户名</th>
									<th>密码</th>
									<th>电话</th>
									<th>送货地址</th>
									<th>注册日期</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach items="${users }" var="user">

									<tr>
										<th><input type="checkbox" name="ids" value="${user.id }" /></th>
										<td id="userid">${user.id}</td>
										<td>${user.name}</td>
										<td>${user.password}</td>
										<td>${user.phone}</td>
										<td>${user.addr}<span class="label label-success">已发货</span></td>
										<td>${user.reg_date}</td>
										<td>
											<div class="btn-group">
												<button class="btn">操作</button>
												<button data-toggle="dropdown" class="btn dropdown-toggle">
													<span class="caret"></span>
												</button>
												<ul class="dropdown-menu">
													<li><a href="javascript:;"
														onclick="resetPassword(${user.id})">重置密码</a> <a
														href="javascript:;" onclick="deleteUser(${user.id})">删除</a></li>
													<!-- delete.user?id=${user.id}  -->
												</ul>

												<script type="text/javascript">
														function deleteUser(id){
															if (confirm("你确定要删除么？")) {
						                                           if (confirm("你真的要删除么？删了就真没了")) {
						                                                      window.location.href = "delete.user?id=" + id;
						                                           }
																}
														}
														function resetPassword(id){
															if (confirm("你确定要重置密码么？")) {
						                                                      window.location.href = "resetPassword.user?id=" + id;
																}
														}
														function batchDelete() {
															var checkedNum= $("input[name='ids']:checked").length;
															if(checkedNum==0){
															    alert("至少选中一项删除！");
																return;
															}

															if(confirm("确定删除选中的用户？")){
															    var userList = new Array();
															    $(":checkbox").each(function(){
															    	if(this.checked==true){
															    		
															    		userList.push($(this).val());	
															    	}
													            });
															    window.location.href = "delete.users?ids="
																	+ userList;
															}
														}
														
														
												</script>

											</div>
										</td>
									</tr>
								</c:forEach>
							</tbody>
						</table>
						<div class="pagination pagination-centered">
							<ul>
								<li class="disabled"><a href="#">&laquo;</a></li>
								<li class="active"><a href="#">1</a></li>
								<li><a href="#">2</a></li>
								<li><a href="#">3</a></li>
								<li><a href="#">4</a></li>
								<li><a href="#">5</a></li>
								<li><a href="#">&raquo;</a></li>
							</ul>
						</div>
					</div>
				</div>
			</div>
			<div id="newUserModal" class="modal hide fade">
				<div class="modal-header">
					<button type="button" data-dismiss="modal" aria-hidden="true"
						class="close">&times;</button>
					<h3>新建用户</h3>
				</div>

				<div class="modal-body">
					<form class="form-horizontal" action="register.user" method="post">
						<div class="control-group">
							<label for="firstname" class="control-label">用户名</label>
							<div class="controls">
								<input type="text" name="name" id="name" placeholder="请输入用户名"
									required="required" />
							</div>
						</div>
						<div class="control-group">
							<label for="inputCurrentPassword" class="control-label">密码</label>
							<div class="controls">
								<input type="password" name="password" id="psw1"
									placeholder="请输入密码" required="required" />
							</div>
						</div>

						<div class="control-group">
							<label for="inputCurrentPassword" class="control-label">确认密码</label>
							<div class="controls">
								<input type="password" id="psw2" placeholder="请再次输入密码"
									required="required" />
							</div>
						</div>

						<div class="control-group">
							<label for="phone" class="control-label">电话</label>
							<div class="controls">
								<input type="text" name="phone" id="phone" placeholder="请输入电话"
									required="required" />
							</div>
						</div>

						<div class="control-group">
							<label for="email_address" class="control-label">送货地址</label>
							<div class="controls">
								<textarea rows="10" cols="30" name="addr" id="addr"
									required="required"></textarea>
							</div>
						</div>

						<div class="modal-footer">
							<a href="#" class="btn">关闭</a><input type="submit"
								class="btn btn-primary" value="添加用户" />
						</div>
					</form>
				</div>

			</div>
		</div>
		<%@include file="footer.jsp"%>
</body>
<script src="js/d3-setup.js"></script>
</html>
